package cl.ccs.portalclientes.model.util;

import java.text.DecimalFormat;


public class NumberUtil {
    private static NumberUtil instance;

    public NumberUtil() {
        super();
    }

    public static NumberUtil getInstance() {
        if (instance == null) {
            instance = new NumberUtil();
        }
        return instance;
    }

    public String numberWithSeparator(Long number) {
        DecimalFormat decimalFormat = new DecimalFormat("###,###.###");
        return decimalFormat.format(number);
    }

    public String numberWithSeparatorWithotD(Long number) {
        DecimalFormat decimalFormat = new DecimalFormat("###,###");
        return decimalFormat.format(number);
    }

    public String amountPdf(Float number) {
        DecimalFormat decimalFormat = new DecimalFormat("###,##0.00");
        return decimalFormat.format(number);
    }


    public String fillWithZeroPdf(Integer number) {
        return String.format("%04d", number);
    }

    public static String formatRut(String rut) {
        int cont = 0;
        String format;
        rut = rut.replace(".", "");
        rut = rut.replace("-", "");
        rut = String.valueOf(Long.parseLong(rut.substring(0, rut.length() - 1))) + rut.substring(rut.length() - 1);

        format = "-" + rut.substring(rut.length() - 1);
        for (int i = rut.length() - 2; i >= 0; i--) {
            format = rut.substring(i, i + 1) + format;
            cont++;
            if (cont == 3 && i != 0) {
                format = "." + format;
                cont = 0;
            }
        }
        return format;
    }

}
